package cn.group.service.impl;

import cn.group.dao.ClassDao;

import cn.group.domain.Classes;
import cn.group.service.ClassService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassServiceImpl implements ClassService {
    private ClassDao classDao;
    @Autowired
    public  ClassServiceImpl(ClassDao classDao){
        this.classDao=classDao;
    }
    @Override
    public List<Classes> getAll() {
        return classDao.queryAll();
    }

    @Override
    public PageInfo<Classes> getAll(Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        List<Classes> classesList=classDao.queryAll();
        System.out.println(classesList.size());
        PageInfo<Classes> pageInfo=new PageInfo<>(classesList);
        return pageInfo;
    }

    @Override
    public Classes getOneById(Integer id) {
        Classes classes=classDao.queryById(id);
        return classes;
    }

    @Override
    public boolean addOne(Classes classes) {
        int result= classDao.insertByClass(classes);
        return result>0;
    }

    @Override
    public boolean removeOne(Classes classes) {
        int result=classDao.deleteByClass(classes);
        return result>0;
    }

    @Override
    public boolean changeOne(Classes classes) {
        int result =classDao.updateByClass(classes);
        return result>0;
    }
}
